home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / ACKSRC.ZIP / MAPEDIT.C < prev    next >
Text File  |  1993-06-20  |  26KB  |  1,298 lines

  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include <mem.h>
  6. #include <alloc.h>
  7. #include <io.h>
  8. #include <fcntl.h>
  9. #include <time.h>
  10. #include <string.h>
  11. #include <sys\stat.h>
  12. #include "ack3d.h"
  13. #include "mapedit.h"
  14.  
  15.     RECT        HotSpots[] = {
  16.             1,25,161,153,    /* 0  Main grid */
  17.             163,23,172,32,    /* 1  Up arrow    */
  18.             163,146,172,155,    /* 2  Dn arrow    */
  19.             0,155,11,164,    /* 3  Lt arrow    */
  20.             152,155,163,164,    /* 4  Rt arrow    */
  21.             186,2,196,130,    /* 5  1st wall    */
  22.             198,2,208,130,    /* 6  2nd wall    */
  23.             210,2,220,130,    /* 7  3rd wall    */
  24.             222,2,232,130,    /* 8  4th wall    */
  25.             259,2,269,130,    /* 9  1st obj    */
  26.             271,2,281,130,    /* 10 2nd obj    */
  27.             283,2,293,130,    /* 11 3rd obj    */
  28.             295,2,305,130,    /* 12 4th obj    */
  29.             4,173,37,185,    /* 13 Load    */
  30.             41,173,75,185,    /* 14 Save    */
  31.             134,173,163,185,    /* 15 Exit    */
  32.             241,22,251,30,    /* 16 blank sq    */
  33.             243,2,249,8,    /* 17 Pass box    */
  34.             80,173,112,185,    /* 18 New    */
  35.             241,41,251,49,    /* 19 Start box */
  36.             241,62,251,70,    /* 20 Up box    */
  37.             241,83,251,91,    /* 21 Dn box    */
  38.             241,103,251,111,    /* 22 Goal box    */
  39.             -1,-1,-1,-1
  40.             };
  41.  
  42.     unsigned    char far    *ScreenBuffer;
  43.  
  44.     unsigned    char        Grid[4096];
  45.  
  46.     unsigned    char        *bMaps[256];
  47.     unsigned    char        *oMaps[256];
  48.         char        GridFile[128];
  49.         char        PalFile[128];
  50.     unsigned    char        Palette[768];
  51.  
  52.         int        GridX;
  53.         int        GridY;
  54.         int        CurrentType;
  55.         int        CurrentSquare;
  56.         int        PassFlag;
  57.         int        ModifiedFlag;
  58.         int        ErrorCode;
  59.  
  60.     unsigned    char        *WallSquares[256];
  61.     unsigned    char        *ObjSquares[256];
  62.  
  63.     unsigned    char        ObjbmNum[256];
  64.  
  65.  
  66.     RECT    WallCoords[] = {
  67.             186,2,196,130,    /* 1st wall  */
  68.             198,2,208,130,    /* 2nd wall  */
  69.             210,2,220,130,    /* 3rd wall  */
  70.             222,2,232,130    /* 4th wall  */
  71.             };
  72.  
  73.     RECT    ObjCoords[] = {
  74.             259,2,269,130,    /* 1st obj   */
  75.             271,2,281,130,    /* 2nd obj   */
  76.             283,2,293,130,    /* 3rd obj   */
  77.             295,2,305,130    /* 4th obj   */
  78.         };
  79.  
  80.     RECT    SpecialActions[] = {
  81.             241,41,251,49,    /* Start box */
  82.             241,62,251,70,    /* Up box    */
  83.             241,83,251,91,    /* Dn box    */
  84.             241,103,251,111    /* Goal box  */
  85.         };
  86.  
  87. #define TOTAL_SPECIAL    4
  88.  
  89.  
  90.         unsigned char Pal0[] = {0,0,0,0,0,0x2A,0,0x2A,0};
  91.         unsigned char Pal11[] = {0x15,0x3f,0x3f,0x3f,0x15,0x15,
  92.                      0x3f,0x15,0x3f};
  93.         unsigned char Pal15[] = {0x3f,0x3f,0x3f,0x3b,0x3b,0x3b,0x37,
  94.                      0x37,0x37};
  95.  
  96.  
  97.  
  98.     BOXES    MsgBox[] = {
  99.         82,48,"mapbox1",1,1,136,81,161,93,0,0,0,0,0,0,0,0,0,0,0,0,
  100.         61,49,"mapbox2",1,2,101,87,132,101,166,87,197,101,0,0,0,0,0,0,0,0,
  101.         61,49,"mapbox3",1,2,101,87,132,101,166,87,197,101,0,0,0,0,0,0,0,0,
  102.         97,54,"mapbox4",0,1,130,88,151,100,0,0,0,0,0,0,0,0,0,0,0,0,
  103.         82,48,"mapbox5",1,1,136,81,161,93,0,0,0,0,0,0,0,0,0,0,0,0,
  104.         82,48,"mapbox6",1,1,136,81,161,93,0,0,0,0,0,0,0,0,0,0,0,0,
  105.         };
  106.  
  107. unsigned char far * Readiff(char *picname);
  108.  
  109. /****************************************************************************
  110. **                                       **
  111. ****************************************************************************/
  112. void SoundBeep(void)
  113. {
  114. sound(440);
  115. delay(50);
  116. nosound();
  117. }
  118.  
  119. /****************************************************************************
  120. **                                       **
  121. ****************************************************************************/
  122. void ScreenToBuffer(int x,int y,int wt,int ht,unsigned char *Buffer)
  123. {
  124.     int        row;
  125.     unsigned char *Video;
  126.  
  127. Video = MK_FP(0xA000,(y * 320) + x);
  128.  
  129. for (row = 0; row < ht; row++)
  130.     {
  131.     memmove(Buffer,Video,wt);
  132.     Buffer += wt;
  133.     Video += 320;
  134.     }
  135.  
  136. }
  137.  
  138. /****************************************************************************
  139. **                                       **
  140. ****************************************************************************/
  141. void BufferToScreen(int x,int y,int wt,int ht,unsigned char *Buffer)
  142. {
  143.     int        row;
  144.     unsigned char *Video;
  145.  
  146. Video = MK_FP(0xA000,(y * 320) + x);
  147.  
  148. for (row = 0; row < ht; row++)
  149.     {
  150.     memmove(Video,Buffer,wt);
  151.     Buffer += wt;
  152.     Video += 320;
  153.     }
  154.  
  155. }
  156.  
  157.  
  158.  
  159. /****************************************************************************
  160. **                                       **
  161. ****************************************************************************/
  162. int ShowMsgBox(int Number)
  163. {
  164.     int        i,handle,len,result;
  165.     int        mx,my,mButton;
  166.     int        x,y,wt,ht;
  167.     char    *BackBuffer;
  168.     char    *BoxBuffer;
  169.     char    size[4];
  170.     char    fName[14];
  171.  
  172. strcpy(fName,MsgBox[Number].FileName);
  173. AddExtent(fName,".bbm");
  174.  
  175. BoxBuffer = Readiff(fName);
  176.  
  177. if (BoxBuffer == NULL)
  178.     return(0);
  179.  
  180. wt = (*(int *)BoxBuffer);
  181. ht = (*(int *)&BoxBuffer[2]);
  182. len = wt * ht;
  183.  
  184. BackBuffer = malloc(len);
  185. if (BackBuffer == NULL)
  186.     {
  187.     free(BoxBuffer);
  188.     return(0);
  189.     }
  190.  
  191. #if 0
  192. handle = open(fName,O_RDWR|O_BINARY);
  193. if (handle < 1)
  194.     return(0);
  195.  
  196. read(handle,size,4);
  197.  
  198. ht = (*(int *)size);
  199. wt = (*(int *)&size[2]);
  200. len = wt * ht;
  201.  
  202. BackBuffer = malloc(len);
  203. BoxBuffer = malloc(len);
  204.  
  205. if (BackBuffer == NULL || BoxBuffer == NULL)
  206.     {
  207.     close(handle);
  208.     return(0);
  209.     }
  210.  
  211. read(handle,BoxBuffer,len);
  212. close(handle);
  213. #endif
  214.  
  215. x = MsgBox[Number].BoxX;
  216. y = MsgBox[Number].BoxY;
  217.  
  218. mouse_hide_cursor();
  219. ScreenToBuffer(x,y,wt,ht,BackBuffer);
  220. BufferToScreen(x,y,wt,ht,&BoxBuffer[4]);
  221. mouse_show_cursor();
  222.  
  223. if (MsgBox[Number].DoBeep)
  224.     SoundBeep();
  225.  
  226. len = 0;
  227.  
  228. while (!len)
  229.     {
  230.     if (inkey() == 0x1C0D)
  231.     break;
  232.  
  233.     mouse_read_cursor(&mButton,&my,&mx);
  234.  
  235.     if (mButton & 1)
  236.     {
  237.     for (i = 0; i < MsgBox[Number].NumButtons; i++)
  238.         {
  239.         if (mx >= MsgBox[Number].ButtonCoords[i].x &&
  240.         mx <= MsgBox[Number].ButtonCoords[i].x1 &&
  241.         my >= MsgBox[Number].ButtonCoords[i].y &&
  242.         my <= MsgBox[Number].ButtonCoords[i].y1)
  243.         {
  244.         result = i;
  245.         mouse_released();
  246.         len = 1;
  247.         break;
  248.         }
  249.         }
  250.  
  251.     }
  252.  
  253.     }
  254.  
  255. mouse_hide_cursor();
  256. BufferToScreen(x,y,wt,ht,BackBuffer);
  257. mouse_show_cursor();
  258.  
  259. free(BackBuffer);
  260. free(BoxBuffer);
  261.  
  262. return(result);
  263. }
  264.  
  265.  
  266.  
  267. /****************************************************************************
  268. **                                       **
  269. ****************************************************************************/
  270. int GetAction(int mx,int my)
  271. {
  272.     int        i = 0;
  273.  
  274. while (1)
  275.     {
  276.     if (HotSpots[i].x < 0)
  277.     return(-1);
  278.  
  279.     if (mx >= HotSpots[i].x &&
  280.     mx <= HotSpots[i].x1 &&
  281.     my >= HotSpots[i].y &&
  282.     my <= HotSpots[i].y1)
  283.     break;
  284.  
  285.     i++;
  286.     }
  287.  
  288. return(i);
  289. }
  290.  
  291. /****************************************************************************
  292. **                                       **
  293. ****************************************************************************/
  294. void ShowScreen(void)
  295. {
  296.     unsigned char far *Video;
  297.  
  298. Video = MK_FP(0xA000,0);
  299. memmove(Video,ScreenBuffer,64000);
  300.  
  301. }
  302.  
  303. /****************************************************************************
  304. **                                       **
  305. ****************************************************************************/
  306. void GetBufferSquare(int x,int y,unsigned char *buffer)
  307. {
  308.     int        row;
  309.     unsigned char *src;
  310.  
  311. src = ScreenBuffer + ((y * 320) + x);
  312.  
  313. for (row = 0; row < 8; row++)
  314.     {
  315.     memmove(buffer,src,10);
  316.     buffer += 10;
  317.     src += 320;
  318.     }
  319. }
  320.  
  321.  
  322. /****************************************************************************
  323. **                                       **
  324. ****************************************************************************/
  325. int BuildSquares(void)
  326. {
  327.         int    i,j,x,y,num;
  328.     unsigned    char    *Square;
  329.  
  330. Square = malloc(80);
  331. if (Square == NULL)
  332.     {
  333.     ErrorCode = ERR_NOMEMORY;
  334.     return(-1);
  335.     }
  336.  
  337. WallSquares[0] = Square;
  338. GetBufferSquare(1,25,Square);
  339.  
  340. num = 1;
  341. for (i = 0; i < 4; i++)
  342.     {
  343.     x = WallCoords[i].x;
  344.     y = WallCoords[i].y;
  345.  
  346.     for (j = 0; j < 16; j++)
  347.     {
  348.     Square = malloc(80);
  349.     if (Square == NULL)
  350.         return(-1);
  351.     WallSquares[num++] = Square;
  352.     GetBufferSquare(x,y,Square);
  353.     y += 8;
  354.     }
  355.  
  356.     }
  357.  
  358. num = 1;
  359. for (i = 0; i < 4; i++)
  360.     {
  361.     x = ObjCoords[i].x;
  362.     y = ObjCoords[i].y;
  363.  
  364.     for (j = 0; j < 16; j++)
  365.     {
  366.     Square = malloc(80);
  367.     if (Square == NULL